package presentation.util;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class ItemButtonGroup implements ActionListener{
	ArrayList<ItemButton> buttonList = new ArrayList<>();
   
	public void add(ItemButton newButton){
		newButton.addActionListener(this);
		buttonList.add(newButton);
		if(buttonList.size()==1){
			buttonList.get(0).setFlag(true);
			buttonList.get(0).setPressed();
		}
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		 ItemButton selectedButton = (ItemButton)e.getSource();
		 selectedButton.setPressed();
		 selectedButton.setFlag(true);
		 for(ItemButton otherButton : buttonList){
			 if(otherButton!=selectedButton){
				 otherButton.setInit();
				 otherButton.setFlag(false);
			 }
		 }
	}
}
